package io.dy.template.impl;

import io.dy.template.ExcelAndPdfExportTemplate;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author : dmj
 * @date: 2024/7/15 9:53 上午
 * @description:
 */
//@Component
public class DemoExportImpl extends ExcelAndPdfExportTemplate {
    @Override
    public ExportType exportType() {
        return ExportType.EXCEL;
    }

    @Override
    public String templateUrl() {
        return "/templates/峰谷通调峰结算单模版.xlsx";
    }

    @Override
    public <T> ExportData exportData(T req) {
        Map<String, Object> map = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年M月d日");
        map.put("shipperName", "南京端点科技有限公司");
        map.put("settlementDate", "2024-07-15");
        map.put("settlementCode", "SC9839723912123");
        //调峰服务费小计行
        map.put("subtotalGas", "20.00");
        map.put("subtotalUnit", "/");
        map.put("subtotalFee", "100.00");
        //峰谷通服务费合计
        map.put("totalGas", "/");
        map.put("totalUnit", "/");
        map.put("totalFee", "20.00");
        map.put("remark", "备注哈哈哈");
        map.put("tabulation", "dy");
        map.put("approval", "sy");
        map.put("finance", "袁童玲");

        map.put("settlementGasSum", "0.00");
        map.put("settlementFeeSum", "0.00");

        map.put("overageGasSum", "10.00");
        map.put("overageFeeSum", "10.00");

        ExportData exportData = new ExportData();

        exportData.setObj(map);

        Map<String, Object> map1 = new HashMap<>();
        map1.put("serialNo", 1);
        map1.put("contractCode", "HT001");
        map1.put("type", "分类");
        map1.put("settlementGas", "10.00");
        map1.put("settlementUnitPrice","1.0");
        map1.put("settlementFee", "10.00");
        List<Map<String, Object>> maps = List.of(map1);

        Map<String, Collection<?>> collectionMap = new HashMap<>();

        collectionMap.put("data", maps);

        List<Map<String, Object>> maps2 = new ArrayList<>();
        for (int i = 1; i < 20; i++) {
            Map<String, Object> map2 = new HashMap<>();
            map2.put("serialNo", i);
            map2.put("contractCode", "HT00" + i);
            map2.put("type", "分类2");
            map2.put("settlementGas", "20.00");
            map2.put("settlementUnitPrice","1.0");
            map2.put("settlementFee", "20.00");
            maps2.add(map2);
        }
        collectionMap.put("data1", maps2);
        exportData.setCollectionMap(collectionMap);
        exportData.setExportFileName("测试demo");
        return exportData;
    }
}
